public class MyQueue {
    static class ListNode{
        private  int val ;
        private  ListNode prev ;
        private  ListNode next ;

        public ListNode(int val) {
            this.val = val;
        }
    }
    private ListNode front ;
    private ListNode rear ;
    private int usedSize ;

    public void offer(int val){
        ListNode node = new ListNode(val) ;
        if(this.front == null){
            this.front = node ;
            this.rear = node ;
        }else{
            node.next = this.front ;
            this.front.prev = node ;
            this.front = node ;
        }
        this.usedSize ++ ;
    }
    public boolean isEmpty(){
        if(this.front == null){
            return true ;
        }
        return false ;
    }
    public int poll(){
        if(isEmpty()){
            throw new MyQueueException("MyQueue is Null") ;
        }
        int ret = this.rear.val ;
        if(this.front == this.rear){
            this.front = null ;
            this.rear = null ;
            this.usedSize = 0 ;
            return ret ;
        }
        this.rear = this.rear.prev ;
        this.rear.next = null ;
        this.usedSize -- ;
        return  ret ;
    }
    public int peek(){
        if(isEmpty()){
            throw new MyQueueException("MyQueue is Null") ;
        }
        return this.rear.val ;
    }

}
